/**
 * Copyright (C) 2013 DaiKit.com - daikit4gxt module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/daikit4gxt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.daikit4gxt.client.ui.edit;

import java.util.List;

import com.daikit.daikit4gxt.client.ui.edit.DualGridAddLeftEvent.DualGridAddLeftHandler;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.sencha.gxt.widget.core.client.event.SelectEvent;


/**
 * Event used in dual grid when items are moved/added from left to right or right to left
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 * @param <M>
 */
@SuppressWarnings("rawtypes")
public class DualGridAddLeftEvent<M> extends GwtEvent<DualGridAddLeftHandler>
{

	/**
	 * Handler type.
	 */
	private static Type<DualGridAddLeftHandler> TYPE;

	private List<M> addedObjects;

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static Type<DualGridAddLeftHandler> getType()
	{
		if (TYPE == null)
		{
			TYPE = new Type<DualGridAddLeftHandler>();
		}
		return TYPE;
	}

	/**
	 * Constructor
	 * 
	 * @param addedObjects
	 *           the added objects
	 */
	public DualGridAddLeftEvent(final List<M> addedObjects)
	{
		this.addedObjects = addedObjects;
	}

	@Override
	public Type<DualGridAddLeftHandler> getAssociatedType()
	{
		return TYPE;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void dispatch(final DualGridAddLeftHandler handler)
	{
		handler.onSelect(this);
	}

	/**
	 * @return the addedObjects
	 */
	public List<M> getAddedObjects()
	{
		return addedObjects;
	}

	/**
	 * @param addedObjects
	 *           the addedObjects to set
	 */
	public void setAddedObjects(final List<M> addedObjects)
	{
		this.addedObjects = addedObjects;
	}

	/**
	 * Handler for {@link DualGridAddLeftEvent} events.
	 * 
	 * @param <M>
	 *           the type of the object to be edited
	 */
	public interface DualGridAddLeftHandler<M> extends EventHandler
	{
		/**
		 * Called after a Edit button is selected.
		 * 
		 * @param event
		 *           the {@link SelectEvent} that was fired
		 */
		void onSelect(DualGridAddLeftEvent<M> event);
	}

	/**
	 * A widget that implements this interface is a public source of {@link SelectEvent} events.
	 * 
	 * @param <M>
	 *           the type of the left object
	 */
	public interface HasDualGridAddLeftHandlers<M>
	{

		/**
		 * Adds a {@link DualGridAddLeftHandler} handler for {@link DualGridAddLeftEvent} events.
		 * 
		 * @param handler
		 *           the handler
		 * @return the registration for the event
		 */
		HandlerRegistration addDualGridLeftAddHandler(DualGridAddLeftHandler<M> handler);


	}
}
